import logging
from voice_assistant.my_state import app_state
from voice_assistant.com_utils import play_notification_sound
from voice_assistant.my_config import WAKE_WORDS

def contains_wake_word(text):
    """检查文本中是否包含任一唤醒词"""
    if not text:
        return False
    text = text.lower().strip()
    return any(wake.lower() in text for wake in WAKE_WORDS)

def handle_wake_word_detection(text):
    """处理唤醒词检测"""
    if contains_wake_word(text):
        logger = logging.getLogger("VoiceAssistant")
        logger.info("检测到唤醒词，触发唤醒")
        app_state.wake_word_detected = True
        app_state.waiting_for_wake = False
        app_state.silence_counter = 0
        app_state.is_recording = True
        play_notification_sound()
        return True
    return False